

using System;
using System.Data;
using System.Diagnostics;
using System.Xml;
using System.ComponentModel;
using System.Collections;
using System.IO;


using CStock;
using CUtil;
using CIndicators;



//problem
//the path var.is not set after deserialization !

//TODO
//Value_Total is not reflecting the current value of the portfolio (Because it would mean an update - and reading 
//of all share data at start
//to update - call Value_TotalUpdate
namespace CStock
{
	[System.Xml.Serialization.XmlRoot()]
	public class PortfolioFactory : Factory , IPortfolioFactory
    {
		#region fields


        IPortfolio portfolio;
        

		#endregion

      

        public PortfolioFactory()
		{
            
            portfolio = new Portfolio();
            this.stockObjectBase = portfolio as StockObjectBase;
            
        }


        public static System.Collections.Specialized.StringCollection Create_PortfolioNames()
        {
            System.Collections.Specialized.StringCollection pn = new System.Collections.Specialized.StringCollection();


            pn.Add("Economy_Bunds");
            pn.Add("Economy_Chemistry");
            pn.Add("Economy_Cars");
            pn.Add("Economy_Food");
            pn.Add("Economy_IT");

            return pn;

        }
        public static IPortfolio CreatePortfolio(string portfolioName)
        {
             
            IPortfolio getPortfolio = new Portfolio();
            getPortfolio.ID = portfolioName;
            //this.AddPortfolio(getPortfolio);
            getPortfolio.Serialize();

            return getPortfolio;

        
        }
        public override bool Create_TestData()
        {
           

            
            IDataItemFactory dif = new DataItemFactory();
            dif.Create("Share1");
            IDataClassFactory dcf = new DataClassFactory();
            dcf.Create("Share1");
            dcf.Create_TestData();

            IDataItem di = dif.StockObjectBase as IDataItem;
            di.DataClass = dcf.StockObjectBase as IDataClass;
            di.Number = 100;
            this.portfolio.DataItems.Items.Add(di);
            //---------------------
            this.portfolio.DataItem_Selected = di;
            //------------

            dif = new DataItemFactory();
            dcf = new DataClassFactory();

            dif.Create("Share2");
            dcf.Create("Share2");
            dcf.Create_TestData();

            di = dif.StockObjectBase as IDataItem;
            di.DataClass = dcf.StockObjectBase as IDataClass;
            di.Number = 100;
            this.portfolio.DataItems.Items.Add(di);




            
            

            return true;


        

        }

      
        public static bool AddTestData(int i)
        {
            return true;

        }
        /// <summary>
        /// attention - new object variable for dataClass!!
        /// </summary>
        /// <returns></returns>
        public override bool DeSerialize()
        {
            if (base.DeSerialize())
            {

                this.portfolio = this.stockObjectBase as IPortfolio;
                return true;

            }
            return false;


           

        }

     
	}
}
